/**
     * id 人物id 唯一标识
     * event ['move','jump','die','create','relive','destory']
     * prop {width,height,color,name,x,y,z,speed}
     * call 回调函数 返回人物的坐标位置和id {x,y,z}
     * */

function createActor(id, event, prop, call) {
    const keySet = new Set(["ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"]); // keyboard press event!
    let { width, height, x, y, z } = { ...prop }; // 获取基础属性
    const data = {
        x: 2,
        y: 0,
        z: 0,
        id: id
    }
    const keyPress = []; // 检测组合键被按下
    keySet.forEach(e => {
        keyPress.push({
            isActive: false,
            keyCode: e
        });
    });
    if (event === "move") {
        window.addEventListener("keydown", function (e) {
            let pressKey = e.key;
            keyPress.map(e => {
                if (e.keyCode === pressKey) {
                    return e.isActive = true
                }
            });
            if (pressKey && keySet.has(pressKey)) {
                e.preventDefault();
                for (const k in keyPress) {
                    let every = keyPress[k];
                    getPostion(pressKey); // 获取移动数据
                    _call(data);
                }
            }
        });
        window.addEventListener("keyup", function (e) {
            let pressKey = e.key;
            if (pressKey && keySet.has(pressKey)) {
                e.preventDefault();
                return;
                keyPress.map(e => {
                    if (e.keyCode === pressKey) {
                        return e.isActive = false;
                    }
                });
            }
        });
    }
    function _call() {
        if (call && typeof call === 'function') {
            call(data);
        }
    }
    function getPostion(key) {
        let _keySet = Array.from(keySet);
        switch (key) {
            case _keySet[0]: // 下
                data['y'] = data['y'] += prop.speed || 1;
                break;
            case _keySet[1]: // 上
                data['y'] = data['y'] -= prop.speed || 1;
                break;
            case _keySet[2]: // 左
                data.x = data.x -= prop.speed || 1;
                break;
            case _keySet[3]: // 右
                data.x = data.x += prop.speed || 1;
                break;
        }
    }
};
/**
 * 
 * @param {*} id 物品id
 * @param {*} prop 物品属性
 * {
 *  width:0,
 *  height:0,
 *  collision:true
 * }
 * 
 */
function createObject(id, prop) {
    const {width,height,collision} = {...prop};
    
 }